package com.cos.lession71.slice;

import com.cos.lession71.ResourceTable;
import ohos.aafwk.ability.AbilitySlice;
import ohos.aafwk.content.Intent;
import ohos.agp.components.Button;
import ohos.agp.components.Component;
import ohos.agp.components.Text;

import java.util.ArrayList;

public class NextAbilitySlice extends AbilitySlice {
    @Override
    protected void onStart(Intent intent) {
        super.onStart(intent);
        setUIContent(ResourceTable.Layout_ability_next);
        //判断非空
        if (intent != null) {
            //接受传递进来的参数
            String username = intent.getStringParam("username");
            int age = intent.getIntParam("age",0);
            ArrayList<String> hobby = intent.getStringArrayListParam("hobby");
            //获取text 文本对象
            Text t  = (Text) findComponentById(ResourceTable.Id_t1);
            //设值
            t.setText(username+"-"+age+"-"+hobby);
        }
        //设值按钮点击事件
        Button btn2 = (Button) findComponentById(ResourceTable.Id_btn2);
        btn2.setClickedListener(new Component.ClickedListener() {
            @Override
            public void onClick(Component component) {
                //Intent
                Intent i = new Intent();
                //设值需要回传的数据
                i.setParam("param","试试就逝世");
                //设值为回传值
                setResult(i);
                //结束当前的Slice生命周期 结束关闭当前这个slice的页面
                terminate();
            }
        });
    }
}
